import axios from 'axios'

// create an axios instance
const service = axios.create({
    headers: {
        "Access-Control-Allow-Origin": "*"
    },
    timeout: 10000 // request timeout
})


// request interceptor

// 响应拦截器

export function get(url, params) {
    return service.get(url, {
        params, // get 请求时带的参数
        timeout: 10000,
        headers: {
            'X-Requested-With': 'XMLHttpRequest'
        }
    })
}
export function del(url, params) {
    return service.delete(url, {
        params, // get 请求时带的参数
        timeout: 10000,
        headers: {
            'X-Requested-With': 'XMLHttpRequest'
        }
    })
}

// 自定义post
export function post(url, data) {
    return service.post(url, qs.stringify(data, { arrayFormat: 'repeat' }), {
        timeout: 10000,
        headers: {
            'X-Requested-With': 'XMLHttpRequest',
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
        }
    })
}

// postJson
export function postJSON(url, data) {
    return service.post(url, data, {
        timeout: 10000,
    })
}

export default service
